
function getAjaxObj(){

	var xhre; 
	try {  xhre = new ActiveXObject('Msxml2.XMLHTTP'); }
	catch (e) 
	{
		try {   xhre = new ActiveXObject('Microsoft.XMLHTTP');	}
		catch (e2) 
		{

		  try { xhre = new XMLHttpRequest();	 }
		  catch (e3) {  xhre = false;   }
		}
	 }
	 return xhre;
}

function AjaxCheck(xhr){

	//	1 : success , 0 : failure , -1 : ignore
	if (xhr.readyState==4 && xhr.status==200)
	{
		return 1;
	}
	else if (xhr.readyState==4 && xhr.status != 200)
	{
		return 0;
	}
	else if (xhr.readyState==2 || xhr.readyState==3 )
	{
		return -1;
	}
	else{
		return -1;
	}
}

//	This is going to be deprecated
function checkAjaxCondition(xhr){
	if (xhr.readyState==4 && xhr.status==200)
	{
		return true;
	}
	return false;
}


function initialize_ajax(command, callback){

	var xhr = getAjaxObj()
	xhr.open('GET', command,  true); 
	xhr.onreadystatechange  = function() { 
		if(AjaxCheck(xhr) == 1) {
			callback(xhr.responseText)
		} 
		else if(AjaxCheck(xhr) == -1){
			//Ignore this signal
		}
		else{
			alert('Internet or server failure, check your connection..')
			window.location.reload(true);
		}

	}; 

	xhr.send(null); 

}

